#pragma once
#include <QWidget>

#include "../CMD/Command.h"

class QJsonObject;
class QHBoxLayout;
class QSpacerItem;
class QLabel;
class SImageButton;

struct MenuItem {
  int cmdId = 0;
  QString title;
  QString abbr;
  Command::CmdTag tag = Command::CmdTag::kNone;
};

class AppMenuItem : public QWidget {
  Q_OBJECT
 public:
  AppMenuItem(QJsonObject* obj, QWidget* parent);
  AppMenuItem(int cmdId, QWidget* parent);

  int cmdId() const { return m_item.cmdId; }
  void setInFav(bool v) { m_isInFav = true; }
  bool isRedPoint();
  bool isEnabled();

 protected:
  void leaveEvent(QEvent* event) override;
  void mouseMoveEvent(QMouseEvent* event) override;
  void mouseReleaseEvent(QMouseEvent* event) override;
  void paintEvent(QPaintEvent* event) override;

 protected slots:
  void onBtnClicked();

 private:
  void construct(QJsonObject* obj);
  void construct(int cmdId);
  void onHoverChanged();

 private:
  MenuItem m_item;
  QHBoxLayout* m_layout = nullptr;
  QLabel* m_labelAbbr = nullptr;
  QLabel* m_labelTitle = nullptr;
  SImageButton* m_btn = nullptr;
  QSpacerItem* m_spacer = nullptr;
  bool m_hover = false;
  static bool s_notifying;
  bool m_isInFav = false;
};
